<template>
	<div>
		<jk-table ref="jkTable" border :span-method="mergeColMethod" :data="tableData" :height="height">
			<vxe-column
				v-for="(item, index) in tableColumnList"
				:key="index"
				:title="item.title"
				:align="item.align"
				:field="item.keyName"
				:sortable="item.sortable"
				:fixed="item.fixed ? item.fixed : ''"
				:min-width="item.minWidth"
				:width="item.width"
			>
				<template slot-scope="scope">
					<jk-common-status v-if="item.keyName === 'auditState'" :status="scope.row.auditState"></jk-common-status>
					<span v-else-if="item.keyName === 'ifBase'">{{ scope.row.ifBase ? '是' : '否' }}</span>
					<span v-else>{{ scope.row[item.keyName] }}</span>
				</template>
			</vxe-column>
		</jk-table>

	</div>
</template>

<script>
    export default {
        props: {
            tableColumnList: {
                type: Array,
                default() {
                    return [];
                }
            },
            tableData: {
                type: Array,
                default() {
                    return [];
                }
            },
            height: {
                type: [String, Number],
                default: 0
            }
        },
        data() {
            return {

            };
        },
        methods: {
            mergeColMethod({ row, _rowIndex, column, visibleData }) {
                const fields = ['processName']; // 根据字段判断数据相同的合并
                const cellValue = row[column.property];
                if (cellValue && fields.includes(column.property)) {
                    const prevRow = visibleData[_rowIndex - 1];
                    let nextRow = visibleData[_rowIndex + 1];
                    if (prevRow && prevRow[column.property] === cellValue) {
                        return { rowspan: 0, colspan: 0 };
                    } else {
                        let countRowspan = 1;
                        while (nextRow && nextRow[column.property] === cellValue) {
                            nextRow = visibleData[++countRowspan + _rowIndex];
                        }
                        if (countRowspan > 1) {
                            return { rowspan: countRowspan, colspan: 1 };
                        }
                    }
                }
            }
        }
    };
</script>
